package io.geekidea.boot.jieanbo.controller;

import io.geekidea.boot.auth.annotation.Permission;
import io.geekidea.boot.common.enums.SysLogType;
import io.geekidea.boot.framework.annotation.Log;
import io.geekidea.boot.framework.page.Paging;
import io.geekidea.boot.framework.response.ApiResult;
import io.geekidea.boot.jieanbo.dto.AiSetDto;
import io.geekidea.boot.jieanbo.query.AiSetQuery;
import io.geekidea.boot.jieanbo.service.AiSetService;
import io.geekidea.boot.jieanbo.vo.AiSetVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * AI设置表 控制器
 *
 * @author geekidea
 * @since 2025-06-04
 */
@Slf4j
@RestController
@Tag(name = "AI设置表")
@RequestMapping("/admin/aiSet")
public class AiSetController {

    @Autowired
    private AiSetService aiSetService;

    /**
     * 添加AI设置表
     *
     * @param dto
     * @return
     * @throws Exception
     */
    @Log(type = SysLogType.ADD)
    @Operation(summary = "添加AI设置表")
    @PostMapping("/addAiSet")
    @Permission("ai:set:add")
    public ApiResult addAiSet(@Valid @RequestBody AiSetDto dto) {
        log.info("添加AI设置表：{}", dto);
        boolean flag = aiSetService.addAiSet(dto);
        return ApiResult.result(flag);
    }

    /**
     * 修改AI设置表
     *
     * @param dto
     * @return
     * @throws Exception
     */
    @Log(type = SysLogType.UPDATE)
    @Operation(summary = "修改AI设置表")
    @PostMapping("/updateAiSet")
    @Permission("ai:set:update")
    public ApiResult updateAiSet(@Valid @RequestBody AiSetDto dto) {
        log.info("修改AI设置表：{}", dto);
        boolean flag = aiSetService.updateAiSet(dto);
        return ApiResult.result(flag);
    }

    /**
     * 删除AI设置表
     *
     * @param id
     * @return
     * @throws Exception
     */
    @Log(type = SysLogType.DELETE)
    @Operation(summary = "删除AI设置表")
    @PostMapping("/deleteAiSet/{id}")
    @Permission("ai:set:delete")
    public ApiResult deleteAiSet(@PathVariable Integer id) {
        log.info("删除AI设置表：{}", id);
        boolean flag = aiSetService.deleteAiSet(id);
        return ApiResult.result(flag);
    }

    /**
     * 获取AI设置表详情
     *
     * @param id
     * @return
     * @throws Exception
     */
    @Operation(summary = "获取AI设置表详情")
    @PostMapping("/getAiSet/{id}")
    @Permission("ai:set:info")
    public ApiResult<AiSetVo> getAiSet(@PathVariable Integer id) {
        log.info("获取AI设置表详情：{}", id);
        AiSetVo aiSetVo = aiSetService.getAiSetById(id);
        return ApiResult.success(aiSetVo);
    }

    /**
     * 获取AI设置表分页列表
     *
     * @param query
     * @return
     * @throws Exception
     */
    @Operation(summary = "获取AI设置表分页列表")
    @PostMapping("/getAiSetPage")
    @Permission("ai:set:page")
    public ApiResult<AiSetVo> getAiSetPage(@Valid @RequestBody AiSetQuery query) {
        log.info("获取AI设置表分页列表：{}", query);
        Paging<AiSetVo> paging = aiSetService.getAiSetPage(query);
        return ApiResult.success(paging);
    }

}
